<!DOCTYPE html>
<html>
<head>
  <title>登入 - 麻雀博客</title>
  <#include "../common/link.ftl">
</head>
<body>

<#include "../common/header.ftl">

<div class="layui-container fly-marginTop">
  <div class="fly-panel fly-panel-user" pad20>
    <div class="layui-tab layui-tab-brief" lay-filter="user">
      <ul class="layui-tab-title">
        <li class="layui-this">登入</li>
        <li><a href="${ctx.contextPath}/user/reg">注册</a></li>
      </ul>
      <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
        <div class="layui-tab-item layui-show">
          <div class="layui-form layui-form-pane">
            <#--<form id="login_form">-->
              <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">手机/邮箱</label>
                <div class="layui-input-inline">
                  <input type="text" id="phone_email" name="phone_email" value="15768884587" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label for="L_pass" class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="password" name="password" value="1" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label for="L_vercode" class="layui-form-label">验证码</label>
                <div class="layui-input-inline">
                  <input style="" type="text" id="imagecode" name="imagecode" required lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid-yzm" style="padding: 0!important;">
                  <img class="pointer" id="img_tag" height="38" src="${ctx.contextPath}/code/captcha.jpg" alt="点击刷新"/>
                </div>
              </div>
              <div class="layui-form-item">
                <button class="layui-btn" lay-filter="*" id="login_btn">立即登录</button>
                <span style="padding-left:20px;">
                  <a href="${ctx.contextPath}/user/forget">忘记密码？</a>
                </span>
              </div>
              <#--<div class="layui-form-item fly-form-app">
                <span>或者使用社交账号登入</span>
                <a href="" onclick="layer.msg('正在通过QQ登入', {icon:16, shade: 0.1, time:0})" class="iconfont icon-qq" title="QQ登入"></a>
                <a href="" onclick="layer.msg('正在通过微博登入', {icon:16, shade: 0.1, time:0})" class="iconfont icon-weibo" title="微博登入"></a>
              </div>-->
            <#--</form>-->
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<#include "../common/footer.ftl">
<script type="text/javascript">
    $('#img_tag').on('click', function(){
        $("#img_tag").attr("src" ,"${ctx.contextPath}/code/captcha.jpg?t=" + $.now());
    });

    $("body").keydown(function() {
        if (event.keyCode == "13") {
            $("#login_btn").click();
        };
    });

    $('#login_btn').on('click', function () {
        var phone = '', email = '';
        var iamgecode_input = $("#imagecode");
        var password_input = $("#password");
        var phone_email_input = $("#phone_email");

        var type = check_phone_email(phone_email_input);
        if (type == "phone") {
            phone = phone_email_input.val();
        }
        if (type == "email") {
            email = phone_email_input.val();
        }
        if (!type || !check_val(iamgecode_input) || !check_val(password_input)) {
            return;
        }

        var imagecode = iamgecode_input.val();
        var password = password_input.val();

        $.ajax({
            url: "${ctx.contextPath}/user/login_action",
            type: "post",
            data: {phone:phone,email:email,password:password,imagecode:imagecode},
            dataType: "json",
            success: function (result) {
                if (result.status == "0") {
                    $('#img_tag').click();
                    error_msg(result.msg);
                } else {
                    success_msg("登入成功");
                    setTimeout(function () {
                        location.href = "${ctx.contextPath}" + result.go;
                    }, 200);
                }
            }
        });

    });

</script>
</body>
</html>